package nc.tb.cube.fmldim.ui;

import nc.tb.cube.fmldim.DimRowColModel;
import nc.tb.cube.fmldim.IFmlDimGroup;
import nc.tb.dim.DimDef;
import nc.tb.pub.util.NtbLogger;
import nc.ui.pub.beans.UITable;
import nc.ui.pub.bill.BillCellEditor;

public class FmlDimGroupCellEditor extends BillCellEditor {

	private UITable m_table = null;
	
	public FmlDimGroupCellEditor(final FmlDimGroupRefPane tbref, UITable table) {
		super(tbref);
		m_table = table;
        delegate = new EditorDelegate() {
            public void setValue(Object value) {
                tbref.setValue((value != null) ? value.toString() : "");
            }
            public Object getCellEditorValue() {
                if (tbref.getFmlDimGroup() == null)
                    return tbref.getText();
                else
                    return tbref.getFmlDimGroup();
            }
        };
	}
    public java.awt.Component getTableCellEditorComponent (
        	javax.swing.JTable table, 
        	Object value, 
        	boolean isSelected, 
        	int row, 
        	int column)
    {
    	if (m_table != null)
    	{
    		DimRowColModel model = (DimRowColModel)m_table.getModel();
	    	try { 
	    		IFmlDimGroup fg = model.getFmlDimGroup(row);
	    		DimDef dd = model.getDimDef(row);
		    	
		        ((FmlDimGroupRefPane) editorComponent).setFmlDimGroup(fg);
		        ((FmlDimGroupRefPane) editorComponent).setDimDef(dd);
	    	} catch (Exception e) {
	    		NtbLogger.printException(e);
			}
    	}
        delegate.setValue(value);
        return editorComponent;
    }

}
